<%@ page pageEncoding="UTF-8"%>
<body>
	<div class="easyui-layout" style="width: 100%; height: 450px;"
		fit="true">
		<div
			data-options="region:'north',split:true,title:'用户信息管理',iconCls:'icon-tip'"
			style="height: 50px; height: 72px;" id="search_box">
			<div>
				<label>
					姓名:
				</label>
				<input type="text" name="loginName" />

				<label>
					身份证号:
				</label>
				<input type="text" name="idnum" />
				<label>
					是否有效:
				</label>
				<select id="isvalid" class="easyui-combobox" panelHeight="auto"
							name="isvalid">
							<option value="">
								--请选择--
							</option>
							<option value="1">
								是
							</option>
							<option value="0">
								否
							</option>
						</select>

						<a class="easyui-linkbutton" data-options="iconCls:'icon-search'"
							onclick="query();">查询</a>
			</div>
		</div>
		<div data-options="region:'center'">
			<table id="dg" title="用户信息列表" url="system/user/main.action"
				toolbar="#toolbar" pagination="true" fitColumns="true"
				singleSelect="true" class="easyui-datagrid" fit="true" singleSelect="false" rownumbers="true">
				<thead>
					<tr>
						 <th field="ck"  checkbox="true"/>
						 <th field="id" width="80" sortable="true">ID</th> 
						 <th field="loginName" width="80" sortable="true">用户名</th>
						 <th field="age" width="80" sortable="true">年龄</th>
						 <th field="sex" width="80" sortable="true">性别</th>
						 <th field="password" width="80" sortable="true">密码</th>
						 <th field="address" width="200" sortable="true">联系地址</th>
					</tr>
				</thead>
			</table>
			<div id="toolbar">
				<a href="javascript:void(0)" class="easyui-linkbutton"
					iconCls="icon-add" plain="true" onclick="newUser()">添加</a>
				<a href="javascript:void(0)" class="easyui-linkbutton"
					iconCls="icon-edit" plain="true" onclick="editUser()">修改</a>
				<a href="javascript:void(0)" class="easyui-linkbutton"
					iconCls="icon-remove" plain="true" onclick="destroyUser()">删除</a>
			</div>
		</div>
	</div>

	<%@ include file="from.jsp"%>
	<script type="text/javascript">
		var url;
		function destroyUser(){
			var row = $('#dg').datagrid('getSelected');
			if (row){
				$.messager.confirm('Confirm','确定要删除当前用户吗？',function(r){
					if (r){
						var index = $('#dg').datagrid('getRowIndex',row);
						$.post('system/user/delete.action',{id:row.id}, function (data){
			              if (data.result.code=='0'){
			                $('#dg').datagrid('deleteRow',index);
			              }
			               $.messager.alert('增加用户', data.result.message, 'info');
			            });
					}
				});
			}else{
				$.messager.alert('系统提示','<div style="margin-top:10px">请选择需要删除的用户记录!</div>','info');
			}
		}
		
		function editUser(){  
            var row = $('#dg').datagrid('getSelected');  
            if (row){  
                $('#add_user_win').dialog('open').dialog('setTitle','修改用户');  
                $('#loginName').val(row.loginName);
   		      	$('#age').val(row.age);
   		      	$('#sex').val(row.sex);
   		      	$('#address').val(row.address);
                url = 'system/user/update.action?user.id='+row.id;  
            }else{
            	$.messager.alert('系统提示','<div style="margin-top:10px">请选择需要修改的用户记录!</div>','info');
            }
        }  
		
		function newUser(){
			$('#add_user_win').dialog('open').dialog('setTitle','新增用户');  
            $('#add_user_form').form('clear');  
            url = 'system/user/add.action';  
		}
	</script>
</body>
